fix(tag-tree): remeasure virtualizer before scrollToIndex on accordion expand#183
Closed
bk-ty wants to merge 1 commit intokenforthewin:mainfrom
Closed
fix(tag-tree): remeasure virtualizer before scrollToIndex on accordion expand#183bk-ty wants to merge 1 commit intokenforthewin:mainfrom
bk-ty wants to merge 1 commit intokenforthewin:mainfrom
Conversation
Two issues with the tag tree virtualizer after expand/collapse: 1. Expand/collapse changed flatTags length but the virtualizer did not remeasure, causing the scroll area to show the wrong total height until the next unrelated re-render. Added a useEffect on flatTags and virtualizer that calls virtualizer.measure() when the tree structure changes. 2. The scroll-to-selected effect read tagIndexMap via the closure's stale capture rather than the latest value at fire time, so the first render after a tag became selected would scroll to index 0 instead of the target tag. Added tagIndexMapRef (updated on every render) so the effect always reads the current map without needing tagIndexMap as a dependency (which would create spurious re-fires).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: tag-tree accordion scrolls to wrong row after expand
Problem
Clicking a tag category in the left-panel accordion scrolls to the correct row only on the second click. On the first click, the virtualizer measures against its pre-expand layout, so the computed offset lands in the wrong place.
Root cause
@tanstack/react-virtualcaches element heights. When an accordion expands, the list gains rows, but the virtualizer doesn't re-measure until its next render pass.scrollToIndexruns against stale offsets and overshoots/undershoots.Fix
Call
virtualizer.measure()beforescrollToIndex, on thetagIndexMapbuilt from the freshly-expanded state. One extra measurement, no behavior change in the non-accordion path.Testing
npx vitest run— 115/115 pass (no regression in existing tag-tree tests).Files
src/components/TagTreePanel.tsx(+17 / −6)